using Perfect.Marshal;
using System.Xml;

namespace editor
{
namespace cfg.fight
{
[System.Serializable]
public  class AttrAreaMinMax :   cfg.EditorReadWriter 
 {

    public cfg.fight.AttributeType attrType ;
     public float minLowerValue ;
     public float minUpperValue ;
     public float maxLowerValue ;
     public float maxUpperValue ;
     


    public const int TYPE_ID = 416728696;

    public override int GetTypeId() {
        return TYPE_ID;
    }


    public override void MarshalCompatible(Perfect.Marshal.Octets os) {
        os.WriteSize(5);
        os.WriteSize(Tag.INT | (1 << Tag.TAG_SHIFT));  os.WriteInt((int)attrType);  
         os.WriteSize(Tag.FLOAT | (2 << Tag.TAG_SHIFT));  os.WriteFloat(minLowerValue);  
         os.WriteSize(Tag.FLOAT | (3 << Tag.TAG_SHIFT));  os.WriteFloat(minUpperValue);  
         os.WriteSize(Tag.FLOAT | (4 << Tag.TAG_SHIFT));  os.WriteFloat(maxLowerValue);  
         os.WriteSize(Tag.FLOAT | (5 << Tag.TAG_SHIFT));  os.WriteFloat(maxUpperValue);  
         
    }

    public override void UnmarshalCompatible(Perfect.Marshal.Octets os) {
        for (int _var_num_ = os.ReadSize(); _var_num_-- > 0; ) {
            int _id_ = os.ReadSize();
            switch (_id_)
            {
            case (Tag.INT | (1 << Tag.TAG_SHIFT)):   attrType = (cfg.fight.AttributeType)(os.ReadInt()); break;  
             case (Tag.FLOAT | (2 << Tag.TAG_SHIFT)):   minLowerValue = os.ReadFloat(); break;  
             case (Tag.FLOAT | (3 << Tag.TAG_SHIFT)):   minUpperValue = os.ReadFloat(); break;  
             case (Tag.FLOAT | (4 << Tag.TAG_SHIFT)):   maxLowerValue = os.ReadFloat(); break;  
             case (Tag.FLOAT | (5 << Tag.TAG_SHIFT)):   maxUpperValue = os.ReadFloat(); break;  
             
            default: Tag.SkipUnknownField(_id_, os); break;
            }
         }
    }
    public override void MarshalXml(XmlWriter ele)
    {
        ele.WriteAttributeString("type", "AttrAreaMinMax");
        ele.WriteStartElement("attrType"); ele.WriteAttributeString("id", "1"); ele.WriteEnum(attrType); ele.WriteEndElement();
         ele.WriteStartElement("minLowerValue"); ele.WriteAttributeString("id", "2"); ele.WriteFloat(minLowerValue); ele.WriteEndElement();
         ele.WriteStartElement("minUpperValue"); ele.WriteAttributeString("id", "3"); ele.WriteFloat(minUpperValue); ele.WriteEndElement();
         ele.WriteStartElement("maxLowerValue"); ele.WriteAttributeString("id", "4"); ele.WriteFloat(maxLowerValue); ele.WriteEndElement();
         ele.WriteStartElement("maxUpperValue"); ele.WriteAttributeString("id", "5"); ele.WriteFloat(maxUpperValue); ele.WriteEndElement();
         
    }

    public override void UnmarshalXml(XmlElement ele)
    {
        foreach (XmlElement e in ele.GetChildren())
        {
            if (int.TryParse(ele.GetAttribute("id"), out var _id_))
            {
                switch (_id_)
                {
                case 1:  attrType = ele.ReadEnum<cfg.fight.AttributeType>(); break; 
                 case 2:  minLowerValue = ele.ReadFloat(); break; 
                 case 3:  minUpperValue = ele.ReadFloat(); break; 
                 case 4:  maxLowerValue = ele.ReadFloat(); break; 
                 case 5:  maxUpperValue = ele.ReadFloat(); break; 
                 
                default: break;
                }
            }
            else
            {
                switch (e.Name)
                {
                case "attr_type":  attrType = ele.ReadEnum<cfg.fight.AttributeType>(); break; 
                 case "min_lower_value":  minLowerValue = ele.ReadFloat(); break; 
                 case "min_upper_value":  minUpperValue = ele.ReadFloat(); break; 
                 case "max_lower_value":  maxLowerValue = ele.ReadFloat(); break; 
                 case "max_upper_value":  maxUpperValue = ele.ReadFloat(); break; 
                 
                default: break;
                }
            }
        }
    }
}
}
}
